import { AxiosPromise } from 'axios';
import http from './config';
import { Response, SecurityPrincipalVo, AuthorityInfoVo, VerificationCodeVo, CustomUserLoginInfo, TaskInfo, ReqTaskInfo, PageVo, RespTaskInfo, ReqTaskOrder, RespTaskOrder, ReqUserInfo, RespUserInfo, ReqProfitIncome, ProfitIncome, RespFileVo, RespProfitIncome, BankCard, ReqBankCard, UserLoginInfo, ReqCashAccountSetInfo, CashAccountSet, ReqSlideshow, Slideshow } from './bean';


class Login {
  public static handleLogin = {
    p: 'userLogin/login',
    r: (params: SecurityPrincipalVo): AxiosPromise<Response<AuthorityInfoVo>> => {
      return http.post(`userLogin/login`, params);
    },
  };

  /**
   * 获取邀请码
   */
  public static getInvitationCode = {
    p: 'userLogin/invitationCode',
    r: (params: {
      ticket: string
    }): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/invitationCode`, params);
    },
  };

  /**
   * 获取验证码
   */
  public static getAuthCode = {
    p: 'userLogin/sendEmailCode',
    r: (params: VerificationCodeVo): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/sendEmailCode`, params);
    },
  };

  /**
   * 校验验证码
   */
  public static validateAuthCode = {
    p: 'userLogin/authEmailCode',
    r: (params: VerificationCodeVo): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/authEmailCode`, params);
    },
  };

  /**
   * 用户注册
   */
  public static handleRegister = {
    p: 'userLogin/saveUser',
    r: (params: CustomUserLoginInfo): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/saveUser`, params);
    },
  };

  /**
   * 登录名验证
   */
  public static checkLoginAccount = {
    p: 'userLogin/isLoginAccount',
    r: (params: {
      loginAccount: string
    }): AxiosPromise<Response<Boolean>> => {
      return http.get(`userLogin/isLoginAccount`, { params });
    },
  };

  public static handleLogout = {
    p: 'userLogin/quitLonin',
    r: (params: {
      ticket: string
    }): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/quitLonin`, params);
    },
  };

  /**
   * 用户余额
   */
  public static getUserBalance = {
    p: 'user/getUserBalance',
    r: (): AxiosPromise<Response<any>> => {
      return http.post(`user/getUserBalance`);
    },
  };

  /**
   * 更新用户信息
   */
  public static updateLoginInfo = {
    p: 'userLogin/updateLoginInfo',
    r: (params: UserLoginInfo): AxiosPromise<Response<any>> => {
      return http.post(`userLogin/updateLoginInfo`);
    },
  };
}


class Api {

  /**
   * 获取任务列表
   */
  public static getTaskList = {
    p: 'task/taskList',
    r: (params: ReqTaskInfo): AxiosPromise<Response<PageVo<RespTaskInfo>>> => {
      return http.post(`task/taskList`, params);
    },
  };

  /**
   * 获取单条任务
   */
  public static getSingleTask = {
    p: 'task/getSingleTask/{taskId}',
    r: (params: {
      taskId: number
    }): AxiosPromise<Response<TaskInfo>> => {
      return http.post(`task/getSingleTask/${params.taskId}`, params);
    },
  };

  /**
   * 获取详情task 不含有 对应的订单信息 
   */
  public static getSingleDetailsTask = {
    p: 'task/getSingleDetailsTask/{taskId}',
    r: (params: {
      taskId: number
    }): AxiosPromise<Response<RespTaskInfo>> => {
      return http.post(`task/getSingleDetailsTask/${params.taskId}`, params);
    },
  };

  /**
   * 订单列表
   */
  public static getOrderList = {
    p: 'taskOrder/taskOrderList',
    r: (params: ReqTaskOrder): AxiosPromise<Response<PageVo<RespTaskOrder>>> => {
      return http.post(`taskOrder/taskOrderList`, params);
    },
  };

  /**
   * 详情
   */
  public static getOrderDetail = {
    p: 'taskOrder/particulars/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<RespTaskOrder>> => {
      return http.post(`taskOrder/particulars/${params.orderId}`, params);
    },
  };


  /**
   * 作废
   */
  public static invalidOrder = {
    p: 'taskOrder/invalid/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/invalid/${params.orderId}`, params);
    },
  };

  /**
   * 取消订单
   */
  public static cancelOrder = {
    p: 'taskOrder/cancel/{orderId}',
    r: (params: {
      orderId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/cancel/${params.orderId}`);
    },
  };


  /**
   * 抢单接口 买家从任务列表抢单
   */
  public static competeOrder = {
    p: 'taskOrder/saveTaskOrder/{taskId}',
    r: (params: {
      taskId: number,
    }): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/saveTaskOrder/${params.taskId}`, params);
    },
  };


  /**
   * 下订单 卖家上传订单截图
   */
  public static placeOrder = {
    p: 'taskOrder/savePlaceOrder',
    r: (params: ReqTaskOrder): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/savePlaceOrder`, params);
    },
  };

  /**
   * 保存评价 买家上传评价截图
   */
  public static saveReview = {
    p: 'taskOrder/saveEvaluate',
    r: (params: ReqTaskOrder): AxiosPromise<Response<any>> => {
      return http.post(`taskOrder/saveEvaluate`, params);
    },
  };

  /**
   * 完成订单 买家确认订单完成
   */
  // public static accomplishOrder = {
  //   p: 'taskOrder/accomplish',
  //   r: (params: any): AxiosPromise<Response<any>> => {
  //     return http.post(`taskOrder/accomplish`, params);
  //   },
  // };

  /**
   * 确认订单 卖家确认
   */
  // public static confirmOrder = {
  //   p: 'taskOrder/notarizeOrder',
  //   r: (params: {
  //     orderId: number,
  //   }): AxiosPromise<Response<any>> => {
  //     return http.post(`taskOrder/notarizeOrder`, params);
  //   },
  // };


  /**
   * 我的账单列表
   */
  public static getMyBill = {
    p: 'pofitIncome/myBill',
    r: (params: ReqProfitIncome): AxiosPromise<Response<PageVo<ProfitIncome>>> => {
      return http.post(`pofitIncome/myBill`, params);
    },
  };

  /**
   * 保存 提现 充值等等
   */
  public static saveProfitIncome = {
    p: 'pofitIncome/save',
    r: (params: ProfitIncome): AxiosPromise<Response<any>> => {
      return http.post(`pofitIncome/save`, params);
    },
  };

  /**
   * 流水明细列表
   */
  public static getProfitIncomeList = {
    p: 'pofitIncome/getPofitIncomeList',
    r: (params: ReqProfitIncome): AxiosPromise<Response<PageVo<RespProfitIncome>>> => {
      return http.post(`pofitIncome/getPofitIncomeList`, params);
    },
  };

  /**
   * 流水明细
   */
  public static getProfitIncomeDetail = {
    p: 'pofitIncome/getProfitIncomeParticulars/{incomeId}',
    r: (params: {
      incomeId: number,
    }): AxiosPromise<Response<PageVo<RespProfitIncome>>> => {
      return http.post(`pofitIncome/getProfitIncomeParticulars/${params.incomeId}`, params);
    },
  };


  /**
   * 买家列表
   */
  public static getUserList = {
    p: 'user/userList',
    r: (params: ReqUserInfo): AxiosPromise<Response<PageVo<RespUserInfo>>> => {
      return http.post(`/user/userList`, params);
    },
  };

  /**
   * 用户列表
   */
  public static getUserInfoList = {
    p: 'user/UserInfoList',
    r: (params: ReqUserInfo): AxiosPromise<Response<PageVo<RespUserInfo>>> => {
      return http.post(`/user/UserInfoList`, params);
    },
  };

  /**
   * 单条用户信息
   */
  public static getSingleUserInfo = {
    p: 'user/singleUserInfo/{userId}',
    r: (params: {
      userId: number,
    }): AxiosPromise<Response<RespUserInfo>> => {
      return http.post(`/user/singleUserInfo/${params.userId}`);
    },
  };

  /**
   * 列表
   */
  public static getMemberProfit = {
    p: 'profitAccrued/getCountAccrued',
    r: (params: {
      source: number,
    }): AxiosPromise<Response<any>> => {
      return http.get(`/profitAccrued/getCountAccrued`, { params });
    },
  };


  /**
   * 获取用户银行卡信息
   */
  public static getCreditCardList = {
    p: 'bankCard/getBankCardList',
    r: (params: BankCard): AxiosPromise<Response<PageVo<BankCard>>> => {
      return http.post(`/bankCard/getBankCardList`, params);
    },
  };


  /**
   * 添加银行卡信息
   */
  public static addCreditCard = {
    p: 'bankCard/save',
    r: (params: BankCard): AxiosPromise<Response<any>> => {
      return http.post(`/bankCard/save`, params);
    },
  };

  /**
   * 获取金额
   */
  public static getProfitAmount = {
    p: 'invitationCode/countAmount',
    r: (params: any): AxiosPromise<Response<any>> => {
      return http.post(`/invitationCode/countAmount`, params);
    },
  };

  /**
   * 获取成员列表
   */
  public static getProfitMembers = {
    p: 'invitationCode/getInviterEarningsList',
    r: (params: any): AxiosPromise<Response<any>> => {
      return http.post(`/invitationCode/getInviterEarningsList`, params);
    },
  };

  /**
   * 获取单条用户信息
   */
  public static saveUserInfo = {
    p: 'user/save',
    r: (params: any): AxiosPromise<Response<RespUserInfo>> => {
      return http.post(`user/save`, params);
    },
  };

  /**
 * 提现账户列表
 */
  public static getAccountList = {
    p: 'cashAccountSet/getCashAccountSetList',
    r: (params: ReqCashAccountSetInfo): AxiosPromise<Response<PageVo<CashAccountSet>>> => {
      return http.post(`/cashAccountSet/getCashAccountSetList`, params);
    },
  };

  /**
   * 保存提现账户
   */
  public static saveAccount = {
    p: 'cashAccountSet/save',
    r: (params: CashAccountSet): AxiosPromise<Response<any>> => {
      return http.post(`/cashAccountSet/save`, params);
    },
  };

    /**
   * 获取轮播图列表
   */
  public static getSlideshowList = {
    p: 'slideshow/getSlideshowList',
    r: (params: ReqSlideshow): AxiosPromise<Response<PageVo<Slideshow>>> => {
      return http.post(`slideshow/getSlideshowList`, params);
    },
  };

}

class FileHandler {
  public static uploadFile = {
    p: 'file/upload',
    r: (params: FormData): AxiosPromise<Response<Array<RespFileVo>>> => {
      return http.post(`/file/upload`, params);
    },
  };
}

export {
  Login,
  Api,
  FileHandler,
}




